package Util;

import java.sql.*;

public class DbUtil {

    public static Connection getconnection() throws ClassNotFoundException, SQLException {
        String driveName = "com.mysql.cj.jdbc.Driver";

        String userName = "root";

        String userPassword = "root";

        String dbName = "talentmarket";

        String url1, url2, url3, url;

        url1 = "jdbc:mysql://localhost:3306/" + dbName;

        url2 = "?user=" + userName + "&password=" + userPassword;

        url3 = "&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai";

        url = url1 + url2 + url3;

        Class.forName(driveName);

        Connection conn = DriverManager.getConnection(url);

        return conn;

    }


    public static void free(Connection conn, Statement sta, ResultSet rs) throws Exception {
        if (conn != null) conn.close();

        if (sta != null) sta.close();

        if (rs != null) rs.close();

    }


}
